You can use straps,
Another solution could be to add a small net to the sides of the shelves.
The milk cans might rattle around a bit, but they won't slip off the edges..
Yet another alternative would be a bathroom anti-slip mat cut to size.
The mats won't have a problem with heavy jugs, but will keep them firmly in place... also no strapping/unstrapping cans, you can take what you like.
Nominally, the mats will stay securely on the cart, but they may stick a bit to the milk cans. If that is a problem, you can find a way to secure them to the cart (eg. glue the mat down or tie it to the cart somehow)
You can also get smaller friction mats that perform the same duty, albeit in one large piece, instead of the bathroom version with holes as shown in the picture. (if hygiene is an issue)
If you can't find them in your local hobby store or hardware store, they have them at various cargo equipment stores on the Internet (a 30'' by 25' mat costs about 35-40 dollars depending on where you look)
Friction mats can be wiped off with water & soap, but be careful with strong cleansers and alcohols, as they can lose their friction and become brittle when exposed too much...
For stacked goods, you have the option of combining the mats with straps or a net for added support. For this I have considered the option of storing the straps/nets in the cart itself, to avoid these tools getting lost.
This allows you to stack your milk cans almost as you please on the two lower levels.
If your cart has wide lips on each shelf (like a standard steel kitchen cart), you can drill a number of holes in each lip.
Fit a suitable net with metal hooks that fit in the holes.
When transporting stacked cans, the nets are stretched between the two shelves like in the picture above.
When not transporting stacked goods, if you leave extra holes for the hooks, you can store the net underneath the shelf above.
I suggest this if hygiene is important, as the nets can also quickly be unhooked and cleaned if needed.
Mount curtain rails on the shelf and under the shelf above, and mount your net to that.
When not in use, the net is pulled aside (like a curtain), and it can be pulled closed when needed.
This is, however not so suitable for hygienic applications, as you'll be adding addtional nooks and crannies to the cart.
Use one large, flexible net (fitting the size of the shelf), and use large lobster clasps (fitting the size of the cart supports).
Drill holes at different levels in the cart supports, and fit them with screws/bolts/pins to hold the clasps securely in place.
Make an additional "storage" pin at the top of the shelf, where the net is stored.
When needed, simply pull the net down on the cargo as tight as you please, and fasten it to the locking pins needed.
You can use a standard flexible cargo net for cars for this option.