Placing/moving containers for some specific loading/unloading goal has been a solved problem for a while.
You can imagine this needs solving pretty hardcore optimization problems.