An emerging new type of ad hoc network, a wireless sensor network, has great potential to be used in many application areas. While each sensor network application has its own particular technical issues, network topology formation and multi-hop routing are two problems that are common to and very important for all applications. The key question is how to organize and keep the network in an optimal topology so that sensor data can be reliably and efficiently sent to sink nodes. In this thesis, we present a new approach to construct a wireless sensor network topology with a long network lifetime and high data delivery rate. Specifically, we designed an anycast routing protocol named Dynamic Anycast Routing to form anycast trees that enable a simple and efficient routing scheme. The protocol was implemented using the sensor network-oriented operating system TinyOS. The protocol was tested both in a simulation environment and on real sensor hardware. Experiments using the TOSSIM simulator demonstrate that our protocol can significantly prolong network lifetime and at the same time maintain a high data delivery rate.