We propose a novel testing and containment strategy in order to contain the spread of SARS-CoV2 while permitting large parts of the population to resume social and economic activity. Our approach recognises the fact that testing capacities are severely constrained in many countries. In this setting, we show that finding the best way to utilise this limited number of tests during a pandemic can be formulated concisely as an allocation problem. Our problem formulation takes into account the heterogeneity of the population and uses pooled testing to identify and isolate individuals while prioritising key workers and individuals with a higher risk of spreading the disease. In order to demonstrate the efficacy of our testing and containment mechanism, we perform simulations using a network-based SIR model. Our simulations indicate that applying our mechanism on a population of $100,000$ individuals with only $16$ tests per day reduces the peak number of infected individuals by approximately $20%$, when compared to the scenario where no intervention is implemented.