Significant research has been devoted to aggregation in sensor networks with a view to optimize its performance. Existing research has mostly concentrated on maximizing network lifetime within a user-given error bound. In general, the greater the error bound, the longer the lifetime. However, in some situations, it may not be realistic for the user to provide an error bound. Instead, the user may want to provide a Quality of Service (QoS) goal that has a combined objective of lifetime and error. Indeed, the error tolerable by the user may depend on how long the sensor network can last. This paper presents an aggregation protocol and related algorithms for reaching such a QoS goal. The key idea is to periodically modify a filter threshold for each sensor in a way that is optimal within the user objective, the key technical method being to translate the problem into a mathematical programming formulation with constraints coming from various sources, such as the user, the sensor network,...