In the functional design process of a mechanical component, the tolerance allocation stage is of primary importance to make the component itself responding to the functional requirements and to cost constraints. Present state-of-the-art approach to tolerance allocation is based on the use of Statistical Tolerance Analysis (STA) software packages which, by means of Monte Carlo simulation, allow forecasting the result of a set of user-selected geometrical and dimensional tolerances. In order to completely automate and optimize this process, this work presents a methodology to allow an automatic tolerance allocation, capable to minimize the manufacturing cost of a single part or assembly. The proposed approach is based on the Monte Carlo method to compute the statistical distribution of the critical to quality characteristics and uses an optimization technique based on Genetic Algorithms. The resulting procedure has been integrated in an off-the-shelf variation analysis software: eM-TolMate (by Siemens AG). Both the description of the optimization algorithm and some practical applications are presented in order to demonstrate the effectiveness of the proposed methodology.