Lateral gene transfers (LGTs) between ancient species contain information about the relative timing of species diversification. Specifically, the ancestors of a donor species must have existed before the descendants of the recipient species. Hence, the detection of a LGT event can be translated into a time constraint between nodes of a phylogeny if donors and recipients can be identified. When a set of LGTs are detected by interpreting the phylogenetic discordance between gene trees and a species tree, the set of all deduced time constraints can be used to order totally the internal nodes and thus produce a ranked tree. Unfortunately LGT detection is still very challenging and all methods produce some proportion of false positives. As a result the set of time constraints is not always compatible with a ranked species tree. We propose an optimization method called MaxTiC (Maximum Time Consistency) for obtaining a ranked species tree that is compatible with a maximum number of time constraints. We give in particular an exact polynomial time method based on dynamic programming to compute an optimal ranked binary tree supposing that a ranked subtree is given and fixed below each of the two children. We turn this principle into a heuristic to solve the general problem and test it on simulated datasets. Under a wide range of conditions, the obtained ranked tree is very close to the real one, confirming the theoretical possibility of dating with transfers by maximizing time consistency.