The location and capacity of express distribution centers and delivery point allocation are mixed-integer programming problems modeled as capacitated location and allocation problems (CLAPs), which may be constrained by the position and capacity of distribution centers and the assignment of delivery points. The solution representation significantly impacts the search efficiency when applying swarm-based algorithms to CLAPs. In a traditional encoding scheme, the solution is the direct representation of position, capacity, and assignment of the plan and the constraints are handled by punishment terms. However, the solutions that cannot satisfy the constraints are evaluated during the search process, which reduces the search efficiency. A general encoding scheme that uses a vector of uniform range elements is proposed to eliminate the effect of constraints. In this encoding scheme, the number of distribution centers is dynamically determined during the search process, and the capacity of distribution centers and the allocation of delivery points are determined by the random proportion and random key of the elements in the encoded solution vector. The proposed encoding scheme is verified on particle swarm optimization, differential evolution, artificial bee colony, and powerful differential evolution variant, and the performances are compared to those of the traditional encoding scheme. Numerical examples with up to 50 delivery points show that the proposed encoding scheme boosts the performance of all algorithms without altering any operator of the algorithm.