How to stack the boxes

I am trying to use the Domain Randomization to stack the boxes.
The goal is to get the rendered image such that boxes of various sizes can be stacked on shelves in a distribution center.
Changing the size and texture of the boxes could be achieved with Domain Randomization.
However, I don’t know how to STACK boxes of different sizes on a specified shelf.

In the sample video of Domain Randomization, it looks like the shelves and boxes are changed randomly.
What is the means by which this is achieved?