The paper presents an original integrated MAC and routing scheme for wireless sensor networks. Our design objective is to elect the next hop for data forwarding by jointly minimizing the amount of signaling to complete a contention and maximizing the probability of electing the best candidate node. Towards this aim, we represent the suitability of a node to be the relay by means of locally calculated and generic cost metrics. Based on these costs, we analytically model the access selection problem through dynamic programming techniques, which we use to find the optimal access policy. Hence, we propose a contention-based MAC and forwarding technique, called Cost and Collision Minimizing Routing (CCMR). This scheme is then thoroughly validated and characterized through analysis, simulation and experimental results.