Algorithm to fill a truck with pallets
This already exists, but might not be what you are looking for.

While this might not be a problem for your application, notice that this is a more general problem than the (already NP-hard) bin packing problem, so for a large amount of crates finding the optimal solution will be hard. 

On the other hand, for a small enough number of crates, brute force might be sufficient. For example, you could round all dimensions to multiples of 10cm and look at the trucks in terms of 10x10 tiles that crates can occupy, giving you a finite (hopefully small enough) number of potential solutions.