Complex engineering and technological processes typically generate data with a non-trivial hierarchical structure. To this end, in this article we propose a full procedure for optimizing such processes through optimal experimental designs and modeling. In order to study a hierarchical structure, several types of experimental factors may arise, making the building of the experimental design challenging. Starting from the analysis of a preliminary dataset and a pilot design including nested, branching, and shared experimental factors, as well as a new type of experimental factor called composite-form-factor, we build a hierarchical D-optimal experimental design using genetic algorithms. We apply our proposal to a real case-study in the rail sector aimed at optimizing the payload distribution of freight trains. In this case-study we also achieve the best train configuration by minimizing the in-train forces. The results are very satisfactory and confirm that our full procedure represents a valid method to be successfully applied for solving similar technological problems.