Box Packing alternative to Packrat

OK, packaging problems are as far as I know very challenging to solve nicely and algorithmically - though not impossible -, but very easy for use humans to do. Evolution seems to have given us the ability to quickly and efficiently discern patterns and react accordingly. This possibly posed a big advantage in our more primal past, when mankind still lived in nature, instead of next to it. The ability to quickly distinguish between the bush and the hidden, stalking sabre tooth tiger made those survive and probably pass on their genes, who had that skill down. The others were breakfast.

Packing boxes or rectangles usually happens within a container: a box that is meant to get filled with other, smaller boxes. In your case, this container would probably be two stories high, or you could define a container for the lower and another one for the top level that get filled separately.

Now, this is quite an involved topic, but I’d look into greedy packing algorithms, since they are an easier topic and should give you an idea on how to tackle this. They are called “greedy” because they use brute force to find a convenient solution.
While looking into it, you should get some ideas on how to structure an approach to your problem. One thing is clear! You need to develop very precise rules for your packing system, otherwise it’s very difficult to tackle this. Think about how you would stack the boxes, and how you could potentially make Grasshopper do something similar.
I don’t know if this can be done with vanilla components. You probably need scripting for this?

Here are some topics from the past that might be helpful: