This paper improves the ant colony optimization (ACO) to optimize the scattered cargo loading problem. Firstly, the concept of scattered cargoes was defined clearly, and a mathematical model was established to maximize the volume utilization under multiple constraints of scattered cargoes. Next, the wall-based loading strategy was put forward to rationalize the spatial arrangement and stabilize the loaded cargoes. After that, the ACO's expectation function was modified to ensure the consistency between cargo selection and the said strategy. In addition, a pheromone heuristic factor and an expected heuristic factor, both of which are dynamically adjustable, were set up to enhance the global search ability of the proposed algorithm, wall-based ACO (WBACO). Finally, three experiments were conducted respectively on classical weakly heterogeneous data, actual production data with weak heterogeneity, and classical strongly heterogeneous data, to verify the performance of our algorithm. In Experiment 1, the WBACO achieved an objective function value 2.6 % higher than the B&R algorithm and 3.1 % higher than the CBGAT. In Experiment 2, the WBACO led the space-based ACO by 6.82 % in average volume utilization and 3.35 % in optimal volume utilization. In Experiment 3, the result of the WBACO was 0.91 % smaller than the B&R algorithm on wtpack7_51, and 6.97 % greater than the latter on wtpack7_74. The experimental results show that the WBACO lays theoretical and practical bases for intelligent loading of scattered cargoes.