Optimal Data Delivery in Wireless Sensor Networks in the Energy and Latency Domains,