This article presents an algorithm for dynamicrouting and wavelength assignment (D-RWA) in an optical WDM network. The approach is based on a genetic algorithm (GA) and it includes a connection admission control (CAC), to provide a network with simultaneous fairness in distance and bandwidth capacity. The algorithm is evaluated by means of computer simulations using a mesh network with two types of node architectures capable of performing traffic grooming. Combining the two types of nodes, the performance of four network configurations is compared. Assuming that one of the two node types is more costly, two sparse node allocations are suggested to maintain the network cost-effective. The algorithm assigns wavelengths to the ligthpaths, routes the traffic streams, manages the grooming of sub-wavelength tributaries onto full wavelength channels, provides fairness, and minimizes the overall blocking probability of connection requests. Numerical results attest the usefulness of the proposed approach considering several scenarios of distance and bandwidth capacity classes of requests. Simultaneous and isolated simulations of the two fairness schemes are also compared, emphasizing the versatility of the algorithm.