The ship has a detailed cargo plan. The plan has the location of each container on the ship and the port for its delivery. The containers that need to be taken off at the port are stacked in groups.
The plan is needed so the crane operator knows which containers to take off the ship. The planners make sure that the crane operator does not need to move too many containers around to get to the ones they need to unload.
Once the required containers are unloaded, the ship may still have many containers to be delivered to other ports. The ship will have a new cargo plan that shows the crane operator where to stack new containers.
As part of the cargo plan, the weight of the containers is spread evenly over the ship. This prevents the ship from becoming unbalanced.