The uncertainty caused by the variability in renewable energy production requires the engagement of consumer-side energy production and consumption to provide sufficient flexibility and reliability for the power grid. This study presents an algorithm for allocating tasks to distributed energy resources allowing consumers to provide flexibility for frequency containment reserves. The task allocation algorithm aims at supporting the plug and play of energy resources, and it avoids the need for hard real-time messages during the coordination of the resources. The algorithm combines a novel control strategy with an information and communication technology architecture. The main decision logic of the algorithm is defined together with the distributed control logic. A prototype implementation of the overall system for frequency control is used to evaluate the performance of the algorithm. The simulation results show that the algorithm achieves the specified objectives, and has advantages compared to the state of the art solution.